home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Frameworks / TransSkel 3.24 / Demos / C Demos / Skel / Skel.c next >
Text File  |  1995-03-21  |  6KB  |  259 lines

  1. /*
  2.  * TransSkel demonstration:  Traditional Skel
  3.  *
  4.  * This program mimics the original Skel application:  one sizable,
  5.  * dragable, non-closable dark gray window, an "About" alert and two
  6.  * dialogs.  Desk accessories supported.
  7.  *
  8.  * 21 Apr 88 Paul DuBois
  9.  * 29 Jan 89 Version 1.01
  10.  * - Conversion for TransSkel 2.0.
  11.  * 12 Jan 91 Version 1.02
  12.  * - Conversion for TransSkel 3.00.
  13.  * 05 Jun 93 Version 1.03
  14.  * - Conversion for THINK C 6.0.
  15.  * 18 Jan 94 Version 1.04
  16.  * - Used TransSkel positioning routines to position About alert and the
  17.  * dialog box on the screen.  The dialog resource also was made initially
  18.  * invisible, since otherwise it appears and then moves.  Also added
  19.  * a user item for outlining the default button.
  20.  * 21 Feb 94
  21.  * - Updated for TransSkel 3.11.
  22.  * 21 Mar 95
  23.  * - Updated for TransSkel 3.19.
  24.  */
  25.  
  26. # include    "TransSkel.h"
  27.  
  28.  
  29. /*
  30.  * Resource numbers
  31.  */
  32.  
  33. # define    fileMenuRes        129        /* File menu */
  34. # define    aboutAlrtRes    1000    /* About box */
  35. # define    theWindRes        260        /* window */
  36. # define    reportDlog        257        /* message dialog box */
  37. # define    aboutStr        128        /* message strings */
  38. # define    rattleStr        129
  39. # define    frightStr        130
  40.  
  41.  
  42. /* dialog item numbers */
  43.  
  44. typedef enum
  45. {
  46.     okayItem = 1,
  47.     messageItem,
  48.     titleItem,
  49.     outlineItem
  50. };
  51.  
  52.  
  53. /* file menu item numbers */
  54.  
  55. typedef enum
  56. {
  57.     rattle = 1,
  58.     frighten,
  59.     /* --- */
  60.     quit = 4
  61. } fileItems;
  62.  
  63.  
  64. static WindowPtr    theWind;
  65.  
  66. /*
  67.  * Menu handles.  There isn't any apple menu here, since TransSkel will
  68.  * be told to handle it itself.
  69.  */
  70.  
  71. static MenuHandle    fileMenu;
  72.  
  73.  
  74. /* -------------------------------------------------------------------- */
  75. /*                        Menu handling procedures                        */
  76. /* -------------------------------------------------------------------- */
  77.  
  78.  
  79. /*
  80.  * Read a string resource and put into the Alert/Dialog paramtext
  81.  * values
  82.  */
  83.  
  84. static void
  85. SetParamText (short strNum)
  86. {
  87. StringHandle    h;
  88. SignedByte        flags;
  89.  
  90.     h = GetString (strNum);
  91.     flags = HGetState ((Handle) h);
  92.     HLock ((Handle) h);
  93.     ParamText (*h, "\p", "\p", "\p");
  94.     HSetState ((Handle) h, flags);
  95. }
  96.  
  97.  
  98. /*
  99.  * Put up a dialog box with a message and an OK button.  The message
  100.  * is stored in the 'STR ' resource whose number is passed as strNum.
  101.  */
  102.  
  103. static void
  104. Report (short strNum)
  105. {
  106. DialogPtr    theDialog;
  107. GrafPtr        savePort;
  108. short        itemHit;
  109.  
  110.     SetParamText (strNum);
  111.     theDialog = GetNewDialog (reportDlog, nil, (WindowPtr) -1L);
  112.     SkelPositionWindow (theDialog, skelPositionOnParentDevice,
  113.                                 FixRatio (1, 2), FixRatio (1, 5));
  114.     GetPort (&savePort);
  115.     SetPort (theDialog);
  116.     SkelSetDlogButtonOutliner (theDialog, outlineItem);
  117.     ShowWindow (theDialog);
  118.     ModalDialog (SkelDlogFilter (nil, true), &itemHit);
  119.     SkelRmveDlogFilter ();
  120.     DisposeDialog (theDialog);
  121.     SetPort (savePort);
  122. }
  123.  
  124.  
  125. /*
  126.  * Handle selection of "About Skel..." item from Apple menu
  127.  */
  128.  
  129. static pascal void
  130. DoAppleMenu (short item)
  131. {
  132.     SetParamText (aboutStr);
  133.     (void) SkelAlert (aboutAlrtRes, SkelDlogFilter (nil, true),
  134.                                             skelPositionOnParentDevice);
  135.     SkelRmveDlogFilter ();
  136. }
  137.  
  138.  
  139. /*
  140.  * Process selection from File menu.
  141.  *
  142.  * Rattle, Frighten    A dialog box with message
  143.  * Quit    Request a halt by calling SkelStopEventLoop().  This
  144.  *        makes SkelMain return.
  145.  */
  146.  
  147. static pascal void
  148. DoFileMenu (short item)
  149. {
  150.     switch (item)
  151.     {
  152.         case rattle:    Report (rattleStr); break;
  153.         case frighten:    Report (frightStr); break;
  154.         case quit:        SkelStopEventLoop (); break;    /* request halt */
  155.     }
  156. }
  157.  
  158.  
  159. /*
  160.  * Initialize menus.  Tell TransSkel to process the Apple menu
  161.  * automatically, and associate the proper procedures with the
  162.  * File and Edit menus.
  163.  *
  164.  * \311 is the ellipsis character.
  165.  */
  166.  
  167. static void
  168. SetUpMenus (void)
  169. {
  170.     SkelApple ("\pAbout Skel\311", DoAppleMenu);
  171.     fileMenu = GetMenu (fileMenuRes);
  172.     (void) SkelMenu (fileMenu, DoFileMenu, nil, false, true);
  173. }
  174.  
  175.  
  176. /* -------------------------------------------------------------------- */
  177. /*                    Window handling procedures                            */
  178. /* -------------------------------------------------------------------- */
  179.  
  180.  
  181. /*
  182.  * On update event, can ignore the resizing information, since the whole
  183.  * window is always redrawn in terms of the current size, anyway.
  184.  * Content area is dark gray except scroll bar areas, which are white.
  185.  * Draw grow box as well.
  186.  *
  187.  * Note that we can assume the current port is set to theWind.
  188.  */
  189.  
  190. static pascal void
  191. Update (Boolean resized)
  192. {
  193. Rect    r;
  194.  
  195.     r = theWind->portRect;        /* paint window dark gray */
  196.     r.bottom -= 15;                /* don't bother painting the */
  197.     r.right -= 15;                /* scroll bar areas */
  198.     FillRect (&r, (ConstPatternParam) &qd.dkGray);
  199.     r = theWind->portRect;        /* paint scroll bar areas white */
  200.     r.left = r.right - 15;
  201.     FillRect (&r, (ConstPatternParam) &qd.white);
  202.     r = theWind->portRect;
  203.     r.top = r.bottom - 15;
  204.     FillRect (&r, (ConstPatternParam) &qd.white);
  205.     DrawGrowIcon (theWind);
  206. }
  207.  
  208.  
  209. static pascal void
  210. Activate (Boolean active)
  211. {
  212.     DrawGrowIcon (theWind);    /* make grow box reflect new window state */
  213. }
  214.  
  215.  
  216. static pascal void
  217. Clobber (void)
  218. {
  219.     DisposeWindow (theWind);
  220. }
  221.  
  222.  
  223. /*
  224.  * Read window from resource file and install handler for it.  Mouse
  225.  * and key clicks are ignored.  There is no close proc since the window
  226.  * doesn't have a close box.  There is no idle proc since nothing is
  227.  * done while the window is in front (all the things that are done are
  228.  * handled by TransSkel).
  229.  */
  230.  
  231. static void
  232. WindInit (void)
  233. {
  234.     if (SkelQuery (skelQHasColorQD))
  235.         theWind = GetNewCWindow (theWindRes, nil, (WindowPtr) -1L);
  236.     else
  237.         theWind = GetNewWindow (theWindRes, nil, (WindowPtr) -1L);
  238.     if (theWind == (WindowPtr) nil)
  239.         return;
  240.     (void) SkelWindow (theWind, nil, nil, Update, Activate, nil,
  241.                     Clobber, nil, false);
  242. }
  243.  
  244.  
  245. /* -------------------------------------------------------------------- */
  246. /*                                    Main                                */
  247. /* -------------------------------------------------------------------- */
  248.  
  249.  
  250. int
  251. main (void)
  252. {
  253.     SkelInit ((SkelInitParamsPtr) nil);    /* initialize */
  254.     SetUpMenus ();                        /* install menu handlers */
  255.     WindInit();                            /* install window handler */
  256.     SkelEventLoop ();                    /* loop 'til Quit selected */
  257.     SkelCleanup ();                        /* clean up */
  258. }
  259.